import javafx.data.pull.Event;

import com.jfxia.arkles.EventNode;
import com.jfxia.arkles.Trigger;
import com.jfxia.arkles.Handler;


// Test XPath decoder
def paths:String[] = [
	"/abc/def" , 
	"/abc/def[@attr='val']" ,
	"abc/def" ,
	"//abc" ,
	"/abc/def//xyz" ,
	"/abc/def//xyz[@attr]" ,
	"/abc//def/[@]"
];
for(p:String in paths) {
	try {
		def t:Trigger = Trigger { path:p; }
		println(t.toString());
	}catch(e:java.lang.Exception) { e.printStackTrace(); }
}

// Test XPath parser

def trigger1:Trigger = Trigger {
	path: "/shop/customerLists/customers";
	eventNode: EventNode {
		name: "customer"
		onStart: function(ev:Event) { println("Start <customer>"); }
		content: [
			EventNode {
				name: "name"
				onText: function(ev:Event) { println("  name={ev.text}"); }
			} ,
			EventNode {
				name: "address"
				onText: function(ev:Event) { println("  address={ev.text}"); }
			}
		]
		onEnd: function(ev:Event) { println("End <customer>"); }
	}
}

def trigger2:Trigger = Trigger {
	path: "/shop/customerLists/customers[@type='online']";
	eventNode: EventNode {
		name: "customer"
		onStart: function(ev:Event) { println("Start online <customer>"); }
		content: [
			EventNode {
				name: "name"
				onText: function(ev:Event) { println("  online name={ev.text}"); }
			} ,
			EventNode {
				name: "address"
				onText: function(ev:Event) { println("  online address={ev.text}"); }
			}
		]
		onEnd: function(ev:Event) { println("End online <customer>"); }
	}
}


def xh:Handler = Handler {
	triggers: [ trigger2,trigger1 ];
	input: (new java.net.URL("{__DIR__}test2.xml")).openStream();
}
xh.parse();
